from django.db import models

# Create your models here.

class UserInfo(models.Model):
    """
    用户详细信息
    """
    telephone = models.CharField(verbose_name="手机号",max_length=11)
    nickname = models.CharField(verbose_name="昵称",max_length=64)
    avatar = models.CharField(verbose_name="头像",max_length=255)
    token = models.CharField(verbose_name="用户Token",max_length=64,null=True,blank=True)
    submit_count = models.PositiveIntegerField(verbose_name="关注数",default=0)
    fans_count = models.PositiveIntegerField(verbose_name="粉丝数",default=0)
    character = models.CharField(verbose_name="个性签名",max_length=64,null=True,blank=True)
    introduction = models.CharField(verbose_name="自我介绍",max_length=64,null=True,blank=True)

class Topic(models.Model):
    """
    话题
    """
    title = models.CharField(verbose_name="话题",max_length=32)
    count = models.PositiveIntegerField(verbose_name="关注度",default=0)
    search_count = models.PositiveIntegerField(verbose_name="搜索次数",default=0)

class News(models.Model):
    """
    动态
    """
    cover = models.CharField(verbose_name="封面",max_length=128)
    content = models.CharField(verbose_name="内容",max_length=255)
    topic = models.ForeignKey(verbose_name="话题",to="Topic",null=True,blank=True,on_delete=models.CASCADE)
    address = models.CharField(verbose_name="位置",max_length=128,null=True,blank=True)
    user = models.ForeignKey(verbose_name="发布者",to="UserInfo",related_name="news",on_delete=models.CASCADE)

    favor_count = models.PositiveIntegerField(verbose_name="赞数",default=0)

    viewer_count = models.PositiveIntegerField(verbose_name="浏览数",default=0)

    commment_count = models.PositiveIntegerField(verbose_name="评论数",default=0)

    create_date = models.DateTimeField(verbose_name="创建时间",auto_now_add=True)

    school = models.ForeignKey(verbose_name="学校",to="SchoolArea",null=True,blank=True,on_delete=models.CASCADE)

    deal_status = models.SmallIntegerField(verbose_name="闲置状态", default=0)

class NewsDetail(models.Model):
    """
    动态详细
    """
    key = models.CharField(verbose_name="腾讯对象存储中的文件名",max_length=128,help_text="用于以后再腾讯对象存储中删除")
    cos_path = models.CharField(verbose_name="腾讯对象存储中图片路径",max_length=128)
    news = models.ForeignKey(verbose_name='动态',to="News",on_delete=models.CASCADE)



class ViewerRecord(models.Model):
    """
    浏览记录
    """
    news = models.ForeignKey(verbose_name="动态",to='News',on_delete=models.CASCADE)
    user = models.ForeignKey(verbose_name="用户",to='UserInfo',on_delete=models.CASCADE)


class CommentRecord(models.Model):
    """
    评论记录表
    """
    news = models.ForeignKey(verbose_name="动态",to="News",on_delete=models.CASCADE)
    content = models.CharField(verbose_name="评论内容",max_length=255)
    user = models.ForeignKey(verbose_name="评论者",to="UserInfo",on_delete=models.CASCADE)
    create_date = models.DateTimeField(verbose_name="评论时间",auto_now_add=True)
    ###relate_name用于指定反向关联的字段，因为两个外键指向同一张表，被指向的表进行反向关联的时候，如果不指定反向关联的字段，就不知道反向关联哪张表
    reply = models.ForeignKey(verbose_name="回复",to="self",null=True,blank=True,on_delete=models.CASCADE,related_name="replys")
    depth = models.PositiveIntegerField(verbose_name="评论层数",default=1)
    root = models.ForeignKey(verbose_name="根评论",to="self",null=True,blank=True,on_delete=models.CASCADE,related_name="roots")

    favor_count = models.PositiveIntegerField(verbose_name="赞数",default=0)


class NewsFavorRecord(models.Model):
    """
    动态赞记录表
    """
    news = models.ForeignKey(verbose_name="动态",to='News',on_delete=models.CASCADE)
    user = models.ForeignKey(verbose_name="点赞用户",to='UserInfo',on_delete=models.CASCADE)



class UserSubmit(models.Model):
    """
    关注
    """
    user = models.ForeignKey(verbose_name="关注者",to="UserInfo",on_delete=models.CASCADE,related_name="users")
    beuser = models.ForeignKey(verbose_name="被关注者",to="UserInfo",on_delete=models.CASCADE,related_name="beusers")


class SchoolArea(models.Model):
    school = models.CharField(verbose_name="学校",max_length=64)
    count = models.PositiveIntegerField(verbose_name="选择次数",default=0)
    search_count = models.PositiveIntegerField(verbose_name="搜索次数",default=0)